package demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import demo.dao.UserDao;
import demo.entity.users;
import demo.returnMsg.Msg;


@Service
@Transactional(rollbackFor = RuntimeException.class)
public class LoginService{

    @Autowired
    private UserDao userDao;
	/**
     * 登录
     * @param user 用户名和密码
     * @return record
     */
    public Msg login(users user) {
    	Msg msg = new Msg();
        try {
            users user1= userDao.findUserById(user.getEmp_id());
            if(user1.getPassword() == user.getPassword()){
            	msg.setMessage("工号或密码错误");
                
            }else{
                msg.setMessage("登录成功");
                msg.setPermission(user1.getJob_id());
                msg.setId(String.valueOf(user1.getEmp_id()));
            }
        } catch (Exception e) {
            msg.setMessage(e.getMessage());
            e.printStackTrace();
        }
        return msg;
    }

}
